package com.orangelife.mobile.washcar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.curry.android.adapter.FatherAdapter;
import com.curry.orangelife.mobile.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 地图定位的适配器
 * Created by ${shz} on 2016/1/25.
 */
public class WashCarChooseAddressAdapter<T> extends FatherAdapter<T> {
    private Context context;
    private List<PoiInfo> list;
    //经度
    private String addrLng;
    //纬度
    private String addrLat;
    //地址
    private String address;

    public WashCarChooseAddressAdapter(Context context, List<PoiInfo> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public BaseAdapter setList(List<T> list) {
        this.list = (List<PoiInfo>) list;
        return WashCarChooseAddressAdapter.this;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(
                R.layout.item_lv_wash_car_choose_address, null);
        ViewHolder viewHolder = null;
        viewHolder = new ViewHolder(convertView);
        convertView.setTag(viewHolder);
        PoiInfo poiInfo = list.get(position);
        viewHolder.tvLocation.setText(poiInfo.name);
        viewHolder.tvLocationAddress.setText(poiInfo.address);
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'item_lv_wash_car_choose_address.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.tvLocation)
        TextView tvLocation;
        @Bind(R.id.tvLocationAddress)
        TextView tvLocationAddress;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
